package com.sphd.emanu.fragment.details.detailcb;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sphd.emanu.R;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.mvp.MVPBaseFragment;
import com.sphd.emanu.pojo.bank.AccountDetailsBean;
import com.sphd.emanu.pojo.bank.DetailsInfo;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class DetailCBFragment extends MVPBaseFragment<DetailCBContract.View, DetailCBPresenter> implements DetailCBContract.View {
    Unbinder unbinder;
    Bundle bundle;
    @BindView(R.id.piao_text)
    TextView piaoText;
    @BindView(R.id.paper_type)
    TextView paperType;
    @BindView(R.id.paper_create_time)
    TextView paperCreateTime;
    @BindView(R.id.paper_num)
    TextView paperNum;
    @BindView(R.id.paper_use)
    TextView paperUse;
    @BindView(R.id.paper_company_hint)
    TextView paperCompanyHint;
    @BindView(R.id.paper_company)
    TextView paperCompany;
    @BindView(R.id.paper_company_linear)
    LinearLayout paperCompanyLinear;
    @BindView(R.id.ju_text)
    TextView juText;
    @BindView(R.id.paper_project_name)
    TextView paperProjectName;
    @BindView(R.id.paper_category)
    TextView paperCategory;
    @BindView(R.id.paper_incom_type_hint)
    TextView paperIncomTypeHint;
    @BindView(R.id.paper_incom_type)
    TextView paperIncomType;
    @BindView(R.id.paper_username)
    TextView paperUsername;
    @BindView(R.id.paper_username_linear)
    LinearLayout paperUsernameLinear;
    @BindView(R.id.paper_summary)
    TextView paperSummary;
    @BindView(R.id.paper_mome)
    TextView paperMome;
    @BindView(R.id.jing_text)
    TextView jingText;
    @BindView(R.id.receive_handlers)
    TextView receiveHandlers;
    @BindView(R.id.financia_handlers)
    TextView financiaHandlers;
    @BindView(R.id.deposit_handlers)
    TextView depositHandlers;
    private AccountDetailsBean accountDetailsBean;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_detail_cb;
    }

    @Override
    protected void initView() {
        unbinder = ButterKnife.bind(this, rootView);
        bundle = getArguments();
        accountDetailsBean = (AccountDetailsBean) bundle.getSerializable(Constant.ACCOUNT_DETAILS_BEAN);
        paperUsernameLinear.setVisibility(View.GONE);

    }

    @Override
    protected void initData() {
        dissProgressDialog();
        mPresenter.getDetail(accountDetailsBean.getId());
    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void setBean(DetailsInfo detailsInfo) {
        dissProgressDialog();
        paperIncomTypeHint.setText("支出方式");
        paperIncomType.setText("转帐支票");
        paperSummary.setText(accountDetailsBean.getSummary());
//        paperCreateTime.setText(accountDetailsBean.getCreateDate());
//        paperCreateTime.setText(detailPresenterImp.getBillPeriod(detailsInfo));
        paperCreateTime.setText(detailsInfo.getContent().getBillPeriod()==null?"":getBillPeriod(detailsInfo));

        paperType.setText(detailsInfo.getContent().getBillCat());
        paperCompany.setText(detailsInfo.getContent().getPayer());
        paperUse.setText(accountDetailsBean.getPurpose());
        paperUsername.setText(accountDetailsBean.getAuditorName());
        paperMome.setText(accountDetailsBean.getMemo());
        paperCategory.setText(getGenre(detailsInfo));
        paperProjectName.setText(getType(accountDetailsBean));
        paperNum.setText("" + detailsInfo.getContent().getBillQuantity());
        receiveHandlers.setText(detailsInfo.getContent().getReceiver());
        financiaHandlers.setText(detailsInfo.getContent().getOperatorName());
        depositHandlers.setText(detailsInfo.getContent().getDepositorName());
    }
    public String getGenre(DetailsInfo detailsInfo) {
        //       genre(类别 1-贷款，2-借款，3-投资款，4-废品，5-其他)

        switch (detailsInfo.getContent().getCategory()) {
            case "1":
                return "贷款";
            case "2":
                return "借款";
            case "3":
                return "投资款";
            case "4":
                return "废品";
            default:
                return "其他";
        }
    }
    public String getBillPeriod(DetailsInfo detailsInfo) {
        //       genre(类别 1-贷款，2-借款，3-投资款，4-废品，5-其他)
        switch (detailsInfo.getContent().getBillPeriod()) {
            case "1":
                return "本月票据";
            case "2":
                return "非本月票据";
            default:
                return "";
        }
    }
    public String getType(AccountDetailsBean accountDetailsBean) {

//        type（项目 1-初始金额冲减,2-转帐交易,3-收入,4-支出
        switch (accountDetailsBean.getType()) {
            case "1":
                return "初始金额冲减";
            case "2":
                return "转帐交易";
            case "3":
                return "收入";
            case "4":
                return "支出";
            default:
                return "其他";

        }
    }
}
